/******************************************************
 *                                                     
 *              Score System               
 *                                                     
 *******************************************************/

/**
 * AbstractServlet.java
 *
 * 网页的响应Servlet
 *
 * @author sundy
 * @version 0.0.1
 * lastModified 2011-01-01
 */

package com.sundy.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sundy.core.Common;
import com.sundy.core.Context;
import com.sundy.core.Utility;

public class AbstractServlet extends HttpServlet {

	/**
	 * 
	 */
	public PrintWriter out;

	private static final long serialVersionUID = -4817337322026744413L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			Context context = Utility.obtainContext(request);
			request.setCharacterEncoding(Common.defaultEncode);
			response.setCharacterEncoding(Common.defaultEncode);
			out = response.getWriter();
			doGet(context, request, response);
		} catch (Exception se) {
			se.printStackTrace();
			Utility.showError(request, response, "未可预料的错误！" + se.getMessage());
		}
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			Context context = Utility.obtainContext(request);
			request.setCharacterEncoding(Common.defaultEncode);
			response.setCharacterEncoding(Common.defaultEncode);
			out = response.getWriter();
			doPost(context, request, response);
		} catch (Exception se) {
			se.printStackTrace();
			Utility.showError(request, response, "未可预料的错误！" + se.getMessage());
		}
	}

	protected void doGet(Context context, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);
	}

	protected void doPost(Context context, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		super.doPost(request, response);
	}
}
